package com.ruoyi.manage.CL253Api.impl;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.CL253Api.VoiceApi;
import com.ruoyi.common.utils.CLUtils;
import com.ruoyi.manage.CL253Api.SendMessageApi;
import com.ruoyi.manage.CL253Api.SendVoiceApi;
import com.ruoyi.manage.CL253Api.request.SendVoiceRequest;
import com.ruoyi.manage.CL253Api.response.SendVoiceResponse;

import java.util.Map;

/**
 * @Author: wwy
 * @Date: 2021/3/5 9:52
 */
public class SendVoiceClient implements SendVoiceApi {
    @Override
    public SendVoiceResponse sendVoiceExecute(SendVoiceRequest sendVoiceRequest) {
        VoiceApi voiceApi = CLUtils.getVoiceApi();
        JSONObject jsonObject = voiceApi.sendVoice(sendVoiceRequest.getPhone(), sendVoiceRequest.getTemplateId(), sendVoiceRequest.getOption());
        Map<String,Object> map = jsonObject.toJavaObject(Map.class);
        String code = String.valueOf(map.get("code"));
        SendVoiceResponse sendVoiceResponse = new SendVoiceResponse();
        if("200000".equals(code)){
            //成功
            Map<String, Object> data = (Map<String, Object>) map.get("data");
            String callId = String.valueOf(data.get("callId"));
            sendVoiceResponse.setSuccess(true);
            sendVoiceResponse.setCallId(callId);

        }else{
            sendVoiceResponse.setSuccess(false);
        }
        return sendVoiceResponse;
    }
}
